Skip to content

Keep matrix-valued X, Y and Z for single-node and single-block models - #76

Draft
alexpghayes wants to merge 1 commit into
mainfrom
fix/single-node-models
Draft

alexpghayes wants to merge 1 commit into
mainfrom
fix/single-node-models

Conversation

@alexpghayes

Copy link
Copy Markdown
Collaborator

Bugs

  • dcsbm(theta = 1, B = matrix(1)) crashed: Matrix(1, 1, 1) returns a unit-diagonal ddiMatrix, and setting its @x fails. The same applied to every one-node, one-block model (chung_lu(theta = 1), erdos_renyi(n = 1), directed_dcsbm() with n = 1 and k = 1).
  • sbm(n = 1, B = diag(2)) crashed: X[idx, ] in sort_by_all_columns() (R/utils.R) dropped to a vector.
  • overlapping_sbm() with k = 1 and sort_nodes = TRUE stored Z (and X) as a plain numeric vector, for the same reason. mmsbm()'s sorting had the same [idx, ] pattern.

Fix

  • Build the k = 1 membership matrices with Matrix(1, nrow = n, ncol = 1, doDiag = FALSE) (dcsbm(), directed_dcsbm(), both Erdős–Rényi constructors). For n > 1 this is the same dgeMatrix as before.
  • drop = FALSE in sort_by_all_columns() and in mmsbm()'s sorting.

Tests

New tests/testthat/test-single-node.R. Fails on main (2 failures, 2 errors), passes here. Full suite passes. No man/ changes.

Merges cleanly with #63, #66, #68, #70 and #71, which touch nearby lines.

NEWS

Left out to avoid conflicting with #59. Suggested bullet under Bug fixes:

  • Models with a single node (e.g. dcsbm(theta = 1, B = matrix(1)), sbm(n = 1, ...)) no longer error, and overlapping_sbm() with a single block now stores Z as a matrix rather than a vector.

🤖 Generated with Claude Code

- Matrix(1, nrow = 1, ncol = 1) returns a unit diagonal ddiMatrix,
  whose `x` slot can't be set, so dcsbm(theta = 1, B = matrix(1)) and
  other one-node, one-block models crashed. Build the k = 1 membership
  matrix with doDiag = FALSE.
- sort_by_all_columns() and mmsbm()'s sorting subset rows without
  drop = FALSE, so sbm(n = 1, B = diag(2)) crashed and overlapping_sbm()
  with k = 1 stored Z as a plain numeric vector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant